﻿Imports FireAndIceSoft.dbFireAndIceDataSetTableAdapters
Imports DevExpress.Utils

Public Class BotonesPersonalizadosSGS
    ''' <summary>
    ''' Función que actualiza las propiedades del botón
    ''' </summary>
    ''' <param name="idBoton">Corresponde al id del botón</param>
    ''' <param name="idProducto">Corresponde al id del item de venta</param>
    ''' <param name="color">Corresponde al color del botón</param>
    ''' <param name="comentario">Corresponde al cometario asignado al botón</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function ActualizarBoton(ByVal idBoton As Integer, ByVal idProducto As Integer, ByVal color As String, ByVal comentario As String) As Boolean
        Try
            Dim sql As String = String.Format("UPDATE boton_personalizado SET idboton={0}, color='{1}', comentario='{2}', iditemventa={3} WHERE idboton = {4}", idBoton, color, comentario, idProducto, idBoton)
            ConexionSGS.EjecutarQueryNonQuery(sql)
            Return True
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de actualizar los botones", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "ActualizarBoton")
            Return False
        End Try

    End Function

    ''' <summary>
    ''' Función que obtiene el precio del item venta
    ''' </summary>
    ''' <param name="idItemVenta">Corresponde al id del item de venta</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function ObtenerPrecioItemVenta(ByVal idItemVenta As Integer) As String
        Try
            Return ConexionSGS.EjecutarQueryScalar("SELECT precioventa from itemventa where iditemventa = " + idItemVenta.ToString)
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de obtener el precio del item de venta", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "ObtenerPrecioItemVenta")
            Return ""
        End Try
    End Function


    ''' <summary>
    ''' Función que obtiene la categoría del item de venta
    ''' </summary>
    ''' <param name="idItemVenta">Corresponde al id del item de venta</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function ObtenerCategoriaItemVenta(ByVal idItemVenta As Integer) As String
        Try
            Return ConexionSGS.EjecutarQueryScalar("SELECT a.descripcion from tipoproducto as a inner join itemventa as b on a.idtipo = b.idtipo where b.iditemventa = " + idItemVenta.ToString)
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de obtener la categoria del item de venta", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "ObtenerCategoriaItemVenta")
            Return ""
        End Try
    End Function

    ''' <summary>
    ''' Función que obtiene el nombre del item de venta
    ''' </summary>
    ''' <param name="idItemVenta">Corresponde al id del item de venta</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function ObtenerNombreItemVenta(ByVal idItemVenta As Integer) As String
        Try
            Return ConexionSGS.EjecutarQueryScalar("SELECT nombre from itemventa where iditemventa = " + idItemVenta.ToString)
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de obtener el nombre del item de venta", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "ObtenerNombreItemVenta")
            Return ""
        End Try
    End Function

    Shared Function ObtenerComentarioBotonPersonalizado(ByVal idBoton As Integer) As String
        Try
            Return ConexionSGS.EjecutarQueryScalar("select comentario from boton_personalizado where idboton = " + idBoton.ToString)
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de obtene el Comentario del boton personalizado", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "ObtenerComentarioBotonPersonalizado")
            Return ""
        End Try
    End Function

    ''' <summary>
    ''' Función que se encarga de personalizar los botones
    ''' </summary>
    ''' <param name="boton">Corresponde al objeto (botón)</param>
    ''' <param name="texto">Corresponde al objeto (textbox)</param>
    ''' <param name="item">Corresponde al registro seleccionado de los botones personalizados</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function PersonalizarBotones(ByRef boton As DevExpress.XtraEditors.SimpleButton, ByRef texto As System.Windows.Forms.TextBox, ByVal item As dbFireAndIceDataSet.boton_personalizadoRow)
        Try
            Dim SuperToolTip As SuperToolTip = New SuperToolTip
            Dim Titulo As ToolTipTitleItem = New ToolTipTitleItem() With {.Text = ObtenerNombreItemVenta(item.iditemventa)}
            Dim Precio As ToolTipItem = New ToolTipItem() With {.Text = String.Format("Precio: {0}", ObtenerPrecioItemVenta(item.iditemventa), ObtenerCategoriaItemVenta(item.iditemventa))}
            Dim Categoria As ToolTipItem = New ToolTipItem() With {.Text = String.Format("Categoría: {0}", ObtenerCategoriaItemVenta(item.iditemventa))}
            Dim Comentario As ToolTipItem = New ToolTipItem() With {.Text = String.Format("Comentario: {0}", ObtenerComentarioBotonPersonalizado(item.idboton))}
            Dim Separador As ToolTipSeparatorItem = New ToolTipSeparatorItem()
            Titulo.Image = My.Resources.CarProduct
            SuperToolTip.Items.Add(Titulo)
            SuperToolTip.Items.Add(Precio)
            SuperToolTip.Items.Add(Categoria)
            SuperToolTip.Items.Add(Separador)
            SuperToolTip.Items.Add(Comentario)
            boton.Text = ObtenerNombreItemVenta(item.iditemventa)
            boton.SuperTip = SuperToolTip
            boton.Cursor = Cursors.Hand
            texto.Text = item.iditemventa.ToString
            Try
                texto.BackColor = Color.FromArgb(item.color)
                texto.ForeColor = Color.FromArgb(item.color)
            Catch ex As Exception
                texto.BackColor = Color.FromArgb(-6632142)
                texto.ForeColor = Color.FromArgb(-6632142)
            End Try

            texto.ReadOnly = True
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al momento de personalizar los botones", ex, My.Resources.StringGlobal.mdlGeneral, "BotonesPersonalizadosSGS", "PersonalizarBotones")
        End Try
        Return True
    End Function

    Shared Function ConstruirMenuRapidoFacturacion(
                                         Optional ByRef txt1 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn1 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt2 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn2 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt3 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn3 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt4 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn4 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt5 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn5 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt6 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn6 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt7 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn7 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt8 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn8 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                         Optional ByRef txt9 As System.Windows.Forms.TextBox = Nothing,
                                         Optional ByRef btn9 As DevExpress.XtraEditors.SimpleButton = Nothing) As Boolean

        Using adaptadorBotonesPersonalizados As New boton_personalizadoTableAdapter
            adaptadorBotonesPersonalizados.Dispose()
            For Each item In adaptadorBotonesPersonalizados.GetData
                Select Case item.idboton
                    ''Pantalla principal
                    Case 1
                        If btn1 IsNot Nothing Then
                            PersonalizarBotones(btn1, txt1, item)
                        End If
                    Case 2
                        If btn2 IsNot Nothing Then
                            PersonalizarBotones(btn2, txt2, item)
                        End If
                    Case 3
                        If btn3 IsNot Nothing Then
                            PersonalizarBotones(btn3, txt3, item)
                        End If
                    Case 4
                        If btn4 IsNot Nothing Then
                            PersonalizarBotones(btn4, txt4, item)
                        End If
                    Case 5
                        If btn5 IsNot Nothing Then
                            PersonalizarBotones(btn5, txt5, item)
                        End If
                    Case 6
                        If btn6 IsNot Nothing Then
                            PersonalizarBotones(btn6, txt6, item)
                        End If
                    Case 7
                        If btn7 IsNot Nothing Then
                            PersonalizarBotones(btn7, txt7, item)
                        End If
                    Case 8
                        If btn8 IsNot Nothing Then
                            PersonalizarBotones(btn8, txt8, item)
                        End If
                    Case 9
                        If btn9 IsNot Nothing Then
                            PersonalizarBotones(btn9, txt9, item)
                        End If
                End Select
            Next
        End Using
        Return True
    End Function

    Shared Function ConstruirMenuRapidoPlatoDinamico(
                                       Optional ByRef txt10 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn10 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt11 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn11 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt12 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn12 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt13 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn13 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt14 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn14 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt15 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn15 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt16 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn16 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt17 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn17 As DevExpress.XtraEditors.SimpleButton = Nothing,
                                       Optional ByRef txt18 As System.Windows.Forms.TextBox = Nothing,
                                       Optional ByRef btn18 As DevExpress.XtraEditors.SimpleButton = Nothing) As Boolean

        Using adaptadorBotonesPersonalizados As New boton_personalizadoTableAdapter
            adaptadorBotonesPersonalizados.Dispose()
            For Each item In adaptadorBotonesPersonalizados.GetData
                Select Case item.idboton
                    ''Plato dinámico
                    Case 10
                        If btn10 IsNot Nothing Then
                            PersonalizarBotones(btn10, txt10, item)
                        End If
                    Case 11
                        If btn11 IsNot Nothing Then
                            PersonalizarBotones(btn11, txt11, item)
                        End If
                    Case 12
                        If btn12 IsNot Nothing Then
                            PersonalizarBotones(btn12, txt12, item)
                        End If
                    Case 13
                        If btn13 IsNot Nothing Then
                            PersonalizarBotones(btn13, txt13, item)
                        End If
                    Case 14
                        If btn14 IsNot Nothing Then
                            PersonalizarBotones(btn14, txt14, item)
                        End If
                    Case 15
                        If btn15 IsNot Nothing Then
                            PersonalizarBotones(btn15, txt15, item)
                        End If
                    Case 16
                        If btn16 IsNot Nothing Then
                            PersonalizarBotones(btn16, txt16, item)
                        End If
                    Case 17
                        If btn17 IsNot Nothing Then
                            PersonalizarBotones(btn17, txt17, item)
                        End If
                    Case 18
                        If btn18 IsNot Nothing Then
                            PersonalizarBotones(btn18, txt18, item)
                        End If
                End Select
            Next
        End Using
        Return True
    End Function

End Class
